package com.learning.controller.teacher;

import com.learning.dto.ExamPaperDTO;
import com.learning.result.Result;
import com.learning.service.IExamPaperService;
import com.learning.vo.ExamPaperVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;


/**
 * 试卷 前端控制器
 *
 * @author mhdtkc
 * @since 2024-5-25
 */
@Api(tags = "试卷相关接口")
@RestController
@RequestMapping("/teacher/examPaper")
public class ExamPaperController {

    @Autowired
    private IExamPaperService examPaperService;


    /**
     * 自动组卷
     *
     * @return
     */
    @ApiOperation("自动组卷")
    @PostMapping("/autoCreate")
    public Result autoCreateExamPaper(@RequestBody ExamPaperDTO examPaperDTO){
        examPaperService.autoCreateExamPaper(examPaperDTO);
        return Result.success();
    }


    /**
     * 手动组卷初始化
     *
     * @return
     */
    @ApiOperation("手动组卷初始化")
    @PostMapping("/manualCreate")
    public Result manualCreateExamPaper(){
        Long examPaperId = examPaperService.manualCreateExamPaper();
        return Result.success(examPaperId);
    }


    /**
     * 查询所有试卷信息
     *
     * @return
     */
    @ApiOperation("查询所有试卷")
    @GetMapping("/list")
    public Result<List<ExamPaperVO>> queryAllExamPaper(){
        List<ExamPaperVO> examPaperList = examPaperService.queryAll();
        return Result.success(examPaperList);
    }


    /**
     * 根据试卷id查询试卷信息
     *
     * @param examPaperId
     * @return
     */
    @ApiOperation("查询一张试卷")
    @GetMapping
    public Result<ExamPaperVO> queryByExamPaperId(Long examPaperId){
        ExamPaperVO examPaperVO = examPaperService.queryByExamPaperId(examPaperId);
        return Result.success(examPaperVO);
    }


    /**
     * 根据试卷id删除试卷
     *
     * @param id
     * @return
     */
    @ApiOperation("删除试卷")
    @DeleteMapping("/{examPaperId}")
    public Result deleteByExamPaperId(@PathVariable(value = "examPaperId") Long id){
        examPaperService.deleteByExamPaperId(id);
        return Result.success();
    }
}
